package com.study.d024chart;

import javafx.application.Application;
import javafx.collections.FXCollections;
import javafx.collections.ObservableList;
import javafx.scene.Scene;
import javafx.scene.chart.BarChart;
import javafx.scene.chart.CategoryAxis;
import javafx.scene.chart.LineChart;
import javafx.scene.chart.NumberAxis;
import javafx.scene.chart.XYChart;
import javafx.scene.chart.XYChart.Data;
import javafx.scene.chart.XYChart.Series;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.stage.Stage;

/**Chart接口 ,   XYChart 子接口 的实现类LineChart
 * LineChart 折线图的使用
*@description
*@author xtayhame
*date 2020年3月18日
*version
*since v1.0
*/
public class LineChartMain extends Application{
	public static void main(String[] args) {
		launch(args);
	}

	@Override
	public void start(Stage stage) throws Exception {
		AnchorPane anchorPane = new AnchorPane();
		HBox hBox = new HBox(10);

		LineChart<String, Number> lineChart1 = getView1();
		LineChart<Number, String> lineChart2 = getView2();
		LineChart<Number, Number> lineChart3 = getView3();
		hBox.getChildren().addAll(lineChart1,lineChart2,lineChart3);
		anchorPane.getChildren().add(hBox);
		stage.setScene(new Scene(anchorPane, 900, 500));
		stage.show();
	}

	public LineChart<String, Number> getView1(){
		CategoryAxis x =new CategoryAxis();
		x.setLabel("月份");

		NumberAxis  y = new NumberAxis();
		y.setLabel("产量");

		ObservableList<XYChart.Series<String,Number>> datas = FXCollections.observableArrayList();

		XYChart.Series<String, Number> xy1 = new XYChart.Series<String, Number>();
		ObservableList<Data<String, Number>> data1 = FXCollections.observableArrayList();
		Data<String, Number> d1 = new Data<String, Number>("一月",23);
		Data<String, Number> d2 = new Data<String, Number>("二月",43);
		Data<String, Number> d3 = new Data<String, Number>("三月",53);
		data1.addAll(d1,d2,d3);
		xy1.setData(data1);
		xy1.setName("生产线一");

		XYChart.Series<String, Number> xy2 = new XYChart.Series<String, Number>();
		ObservableList<Data<String, Number>> data2 = FXCollections.observableArrayList();
		Data<String, Number> d4 = new Data<String, Number>("一月",83);
		Data<String, Number> d5 = new Data<String, Number>("二月",51);
		Data<String, Number> d6 = new Data<String, Number>("三月",29);
		data2.addAll(d4,d5,d6);
		xy2.setData(data2);
		xy2.setName("生产线二");


		datas.add(xy1);
		datas.add(xy2);

		LineChart<String,Number> lineChart=new LineChart(x, y);
		lineChart.setData(datas);

		//是否显示空心原点
		lineChart.setCreateSymbols(true);

		lineChart.setTitle("全年产量表一");
		return lineChart;
	}

	/**
	 * x轴为数字，y轴为字符串
	 * @return
	 */
	public LineChart<Number,String> getView2(){
		CategoryAxis x =new CategoryAxis();
		x.setLabel("月份");

		NumberAxis  y = new NumberAxis();
		y.setLabel("产量");

		ObservableList<XYChart.Series<Number,String>> datas = FXCollections.observableArrayList();

		XYChart.Series<Number,String> xy1 = new XYChart.Series<Number,String>();
		ObservableList<Data<Number,String>> data1 = FXCollections.observableArrayList();
		Data<Number,String> d1 = new Data<Number,String>(23,"一月");
		Data<Number,String> d2 = new Data<Number,String>(43,"二月");
		Data<Number,String> d3 = new Data<Number,String>(53,"三月");
		data1.addAll(d1,d2,d3);
		xy1.setData(data1);
		xy1.setName("生产线一");

		XYChart.Series<Number,String> xy2 = new XYChart.Series<Number,String>();
		ObservableList<Data<Number,String>> data2 = FXCollections.observableArrayList();
		Data<Number,String> d4 = new Data<Number,String>(83,"一月");
		Data<Number,String> d5 = new Data<Number,String>(51,"二月");
		Data<Number,String> d6 = new Data<Number,String>(29,"三月");
		data2.addAll(d4,d5,d6);
		xy2.setData(data2);
		xy2.setName("生产线二");


		datas.add(xy1);
		datas.add(xy2);

		LineChart<Number,String> lineChart=new LineChart(y,x);
		lineChart.setData(datas);

		lineChart.setTitle("全年产量表二");
		return lineChart;
	}


	//x,y轴都是数字
	public LineChart<Number, Number> getView3(){
		NumberAxis  x = new NumberAxis();
		x.setLabel("月份");

		NumberAxis  y = new NumberAxis();
		y.setLabel("产量");

		ObservableList<XYChart.Series<Number,Number>> datas = FXCollections.observableArrayList();

		XYChart.Series<Number, Number> xy1 = new XYChart.Series<Number, Number>();
		ObservableList<Data<Number, Number>> data1 = FXCollections.observableArrayList();
		Data<Number, Number> d1 = new Data<Number, Number>(10,23);
		Data<Number, Number> d2 = new Data<Number, Number>(20,43);
		Data<Number, Number> d3 = new Data<Number, Number>(30,53);
		data1.addAll(d1,d2,d3);
		xy1.setData(data1);
		xy1.setName("生产线一");

		XYChart.Series<Number, Number> xy2 = new XYChart.Series<Number, Number>();
		ObservableList<Data<Number, Number>> data2 = FXCollections.observableArrayList();
		Data<Number, Number> d4 = new Data<Number, Number>(10,83);
		Data<Number, Number> d5 = new Data<Number, Number>(20,51);
		Data<Number, Number> d6 = new Data<Number, Number>(30,29);
		data2.addAll(d4,d5,d6);
		xy2.setData(data2);
		xy2.setName("生产线二");


		datas.add(xy1);
		datas.add(xy2);

		LineChart<Number,Number> lineChart=new LineChart(x, y);
		lineChart.setData(datas);

		lineChart.setTitle("全年产量表三");
		return lineChart;
	}


}
